import get user model django

39

>>> from django.contrib.auth.models import User
>>> user = User.objects.create_user('john', '[email protected]', 'johnpassword')

# At this point, user is a User object that has already been saved
# to the database. You can continue to change its attributes
# if you want to change other fields.
>>> user.last_name = 'Lennon'
>>> user.save()
from django.contrib.auth import get_user_model

User = get_user_model()
def sample_view(request):
    current_user = request.user
    print current_user.id

Comments

Submit
0 Comments